{layout name="../common/master"/}
<div id="right">
       <h4 style="border-bottom: 1px solid #ccc;padding-bottom: 3px">打款退回待交易列表</h4>
    <form action="" method="get" role="form">
        <div class="form-group">
            <label for="">多用户电话：</label>
            <textarea name="manyUserPhone" id="" cols="30" rows="10">
                {if condition="isset($_GET['manyUserPhone'])"} {$_GET['manyUserPhone']} {/if}
            </textarea>
            <br>

            <label for="">单用户电话：</label>
            <input name="Phone" {if condition="isset($_GET['Phone'])"} value="{$_GET['Phone']}" {/if} type="text"/>

            <label for="">交易时间：</label>
            <input name="upCreateTime" {if condition="isset($_GET['upCreateTime'])"} value="{$_GET['upCreateTime']}" {/if} type="text" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"/>
            ~
            <input name="downCreateTime" {if condition="isset($_GET['downCreateTime'])"} value="{$_GET['downCreateTime']}" {/if} type="text" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"/>

        </div>
        <button type="submit" class="btn btn-primary">查询</button>
    </form>
    <div>
        <button id="extend" type="submit" class="btn btn-info">导出到EXCEL</button>
        <button id="manySuccess" type="submit" class="btn btn-success">一键成功</button>
        <button id="sms" type="submit" class="btn btn-primary">发送短信</button>
        <button id="app" type="submit" class="btn btn-danger">发送推送</button>
        <button id="voice" type="submit" class="btn btn-success">发送语音</button>
        <!--<button id="manyUnsuccess" type="submit" class="btn btn-danger">一键失败</button>-->
    </div>
    <table class="table-bordered table  table-hover" style="margin-top: 20px;">
        <thead>
        <tr>
            <th>ID</th>
            <th>用户ID</th>
            <th>用户电话</th>
            <th>借款ID</th>
            <th>交易状态</th>
            <th>用户银行卡</th>
            <th>打款金额</th>
            <th>创建时间</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {foreach name="data" item="vo" key="k"}
            <tr>
                <th><a target="_blank" href="{:URL('home/Userloan/userLoanInfo',['uid'=>$vo['user_loan_id']])}">{$vo['id']}</a></th>
                <th>{$vo['user_id']}</th>
                <th>{$vo['user_phone']}</th>
                <th>{$vo['user_loan_id']}</th>
                {if condition="$vo['payed_status'] eq 'pending'"}
                   <th>交易中</th>
                {elseif condition="$vo['payed_status' eq 'resolve']"}
                   <th>成功</th>
                {elseif condition="$vo['payed_status' eq 'reject']"}
                   <th>失败</th>
                {/if}
                <th>{$vo['user_bank_card']}</th>
                <th>{$vo['money']}</th>
                <th>{$vo['create_time']}</th>
                <th>
                    <div class="btn-group">
                        <!--<a style="margin-left: 5px" href="{:URL('home/Userloan/userLoanInfo',['uid'=>$vo['id'],'type'=>1])}" class="btn btn-primary btn-sm">查看详情</a>-->
                        <button style="margin-left: 5px" uid="{$vo['id']}" class="success btn btn-success btn-xs">打款成功</button>
                        <!--<button style="margin-left: 5px" uid="{$vo['id']}" userId="{$vo['user_id']}" userPhone="{$vo['user_phone']}" class="record btn btn-primary btn-xs">打款记录</button>-->
                        {if condition="session('username') eq 'admin'"}
                        <button style="margin-left: 5px" uid="{$vo['id']}" class="unsuccess btn btn-danger btn-xs">打款失败</button>
                        {/if}
                        {if condition="$vo['payed_user_info'] neq 9"}
                        <button style="margin-left: 5px" uid="{$vo['user_phone']}" transactionId="{$vo['id']}" class="relayGetMoney btn btn-info btn-xs">延迟放款</button>
                        {else/}
                        <button style="margin-left: 5px" uid="{$vo['user_phone']}" transactionId="{$vo['id']}" class="relayGetMoney btn btn-warning btn-xs">延迟放款</button>
                        {/if}
                    </div>
                </th>
            </tr>
        {/foreach}
        </tbody>
    </table>
    {$page} 总数：{$totalCount}  跳到 <input id="jumpTo" type="number" style="width: 40px"> 页 <button id="jump">跳转</button>

</div>
<script>
    $("#extend").click(function () {
        var url="{:URL('home/Transaction/payFailedList',$_GET)}";
        url=url+"&extend=1";
        location.href=url;
    })
    $("#manySuccess").click(function () {
        var data='{:json_encode($allData)}';
        data=JSON.parse(data);
        var smsContent=`
        <table class="table table-hover table-bordered">
                <thead>
                <tr>
                <th>用户电话</th>
                </tr>
                </thead>
                <tbody>
                              `

              for(let k in data){
                  smsContent += "<tr><td>" + data[k].user_phone+"</td></tr>"
              }
        smsContent +=  `
        </tbody>
        </table>
`
        layer.open({
            title:"确认交易成功用户列表",
            content: smsContent,
            yes: function(index, layero){
                $.post("{:URL('home/Transaction/manySuccess')}",{data:data},function(res){
                    if(res.code == 0){
                        layer.alert('success');
                        location.reload();
                    }else{
                        layer.alert(res.data);
                    }
                })
                layer.close(index); //如果设定了yes回调，需进行手工关闭
            }
        });
    })
    $("#manyUnsuccess").click(function () {
        var data={$totalData};
        $.post("{:URL('home/Transaction/manyUnsuccess')}",{data:data},function(res){
            if(res.code == 0){
                layer.alert('success');
                location.reload();
            }else{
                layer.alert(res.data);
            }
        })
    })
    $(".success").click(function () {
        var uid=$(this).attr('uid');
        $.post("{:URL('home/Transaction/transactionSuccess')}",{uid:uid}, function (res) {
            if(res.code == 0){
                layer.alert('success');
                location.reload();
            }else{
                layer.alert(res.data);
            }
        })
    })
    $(".unsuccess").click(function () {
        var uuid=$(this).attr('uid');
        layer.confirm('transaction failure, sure?', {
            'title':"message",
            btn: ['OK','cancel'] //按钮
        }, function(){
            $.post("{:URL('home/Transaction/transactionFailed')}",{uuid:uuid}, function (res) {
                if(res.code == 0){
                    layer.alert('success');
                    location.reload();
                }else{
                    layer.alert(res.data);
                }
            })
        }, function(){

        });
    })
    $(".relayGetMoney").click(function () {
        var uid=$(this).attr('uid');
        var transactionId=$(this).attr('transactionId');
        var smstmp="Dear customer, sorry to tell that since the bank is off duty, the loan transfer has been submitted to bank and will be disbursed within next work day.Thank you.FlashCash";
        $.post("{:URL('home/Sms/activeSendSms')}",{phone:uid,smstmp:smstmp,transactionId:transactionId}, function (res) {
            if(res.code == 0){
                layer.alert('success');
                location.reload();
            }else{
                layer.alert(res.data);
            }
        })
    })
    $("#jump").click(function(){
        var jumpTo=$("#jumpTo").val();
        var url=location.href;
        var urlPreg=/\?+/;
        if(urlPreg.test(url)){
            url += "&p="+jumpTo;
        }else{
            url += "?p="+jumpTo;
        }
        location.href=url;
    })
    $(".record").click(function(){
      var id=$(this).attr('uid');
      var userPhone=$(this).attr('userPhone');
      var userId=$(this).attr('userId');
        var transactionFailedContent=`
        <select name="transactionFailed" id="inputID" class="form-control">
                <option value="1" selected>银行卡号有误</option>
        </select>
        `;
        layer.open({
            title:"失败原因",
            content: transactionFailedContent,
            yes: function(index, layero){
                var failedReson=$("select[name='transactionFailed'] option:selected").val()
                $.post("{:URL('home/Transaction/record')}",{uid:id,failedReson:failedReson,userPhone:userPhone,userId:userId},function(res){
                    if(res.code == 0){
                        layer.alert('success');
                        location.reload();
                    }else{
                        layer.alert(res.data);
                    }
                })
                layer.close(index); //如果设定了yes回调，需进行手工关闭
            }
        });
    })

    $("#sms").click(function () {
                var html=`
                <form  action="" method="post" role="form">
                        <label for="">选择短信模板</label>
                        <select name="smsTmp" id="smsTmp" class="form-control">
                        <option value=""> -- Select One --</option>
                {foreach name="smsTmp" item="vo" key="k"}
            <option value="{$vo['content']}" num="{$vo['tmp_num']}">{$vo['name']}</option>
            {/foreach}
    </select>
    </form>
    `;
    layer.open({
        btn:['发送'],
        title:'发送催款短信',
        area:['300px','300px'],
        content:html,
        yes:(function(){
            var smstmp=$("#smsTmp option:selected").val();
            var num=$("#smsTmp option:selected").attr('num');
            var phone={$phone};
            $.post("{:URL('home/Sms/onlySendSms')}",{smstmp:smstmp,phone:phone,tmp_num:num},function(res){
                if(res.code ==0){
                    layer.alert(res.msg);
                }else{
                    layer.alert(res.data);
                }
            })
        })
    })
    })

    $("#app").click(function(){
                var html=`
                <form  action="" method="post" role="form">
                        <label for="">选择短信模板</label>
                        <select name="smsAppTmp" id="smsAppTmp" class="form-control">
                        <option value=""> -- Select One --</option>
                {foreach name="appSmsTmp" item="vo" key="k"}
            <option value="{$vo['content']}">{$vo['name']}</option>
            {/foreach}
    </select>
    </form>
    `;
    layer.open({
        btn:['推送'],
        title:'发送催款推送',
        area:['300px','300px'],
        content:html,
        yes:(function(){
            var smstmp=$("#smsAppTmp option:selected").val();
            var phone={$phone};
            $.post("{:URL('home/Sms/onlySendPush')}",{smstmp:smstmp,phone:phone},function(res){
                if(res.code ==0){
                    layer.alert(res.msg);
                }else{
                    layer.alert(res.data);
                }
            })
        })

    })
    })

    $("#voice").click(function(){
                var html=`
                <form  action="" method="post" role="form">
                        <label for="">选择语音模板</label>
                        <select name="smsVoiceTmp" id="smsVoiceTmp" class="form-control">
                        <option value=""> -- Select One --</option>
                {foreach name="smsVoiceTmp" item="vo" key="k"}
            <option value="{$vo['content']}">{$vo['name']}</option>
            {/foreach}
    </select>
    </form>
    `;
    layer.open({
        btn:['推送'],
        title:'发送催款推送',
        area:['300px','300px'],
        content:html,
        yes:(function(){
            var smstmp=$("#smsVoiceTmp option:selected").val();
            var phone={$phone};
            $.post("{:URL('home/Sms/onlySendVoice')}",{smstmp:smstmp,phone:phone},function(res){
                if(res.code ==  0){
                    layer.alert(res.msg);
                }else{
                    layer.alert(res.msg);
                }
            })
        })

    })
    })
</script>
<script type="text/javascript" src="__PUBLIC__/home/tuo/DatePicker/WdatePicker.js"></script>
